package com.hmys.api.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hmys.api.mapper.WebHouseMapper;
import com.hmys.api.model.*;
import com.hmys.api.service.WebHouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * Created by chen365 on 2018/03/27.
 */
@Service
public class WebHouseServiceImpl implements WebHouseService {
    @Autowired
    private WebHouseMapper webHouseMapper;

    @Override
    public PageInfo<WebHouse> selectByBean(Integer pageIndex, Integer pageSize, WebHouseParam record) {
        if (StringUtils.isEmpty(pageIndex) || pageIndex < 1) {
            pageIndex = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 1) {
            pageSize = 10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        List<WebHouse> list = webHouseMapper.selectByBean(record);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<WebHouse> selectByBean(Integer pageIndex, Integer pageSize, WebHouseParamMultiple record) {
        if (StringUtils.isEmpty(pageIndex) || pageIndex < 1) {
            pageIndex = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 1) {
            pageSize = 10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        List<WebHouse> list = webHouseMapper.selectByMultipleBean(record);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<WebHouseSimple> selectSimpleByBean(Integer pageIndex, Integer pageSize, WebHouseParam record) {
        if (StringUtils.isEmpty(pageIndex) || pageIndex < 1) {
            pageIndex = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 1) {
            pageSize = 10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        List<WebHouseSimple> list = webHouseMapper.selectSimpleByBean(record);
        return new PageInfo<>(list);
    }

    @Override
    public PageInfo<WebHouse> selectByCollection(Integer pageIndex, Integer pageSize, Long userId) {
        if (StringUtils.isEmpty(pageIndex) || pageIndex < 1) {
            pageIndex = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 1) {
            pageSize = 10;
        }
        PageHelper.startPage(pageIndex, pageSize);
        List<WebHouse> list = webHouseMapper.selectByCollection(userId);
        return new PageInfo<>(list);
    }

    @Override
    public WebHouseWithBLOBs selectByPrimaryKey(Long id) {
        webHouseMapper.updatePageViewByPrimaryKey(id);
        return webHouseMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<WebHouseWithBLOBs> selectByIds(List<Long> ids) {
        return webHouseMapper.selectByIds(ids);
    }
}
